package com.jeasonzhao.model.hibernate;

import java.util.Hashtable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class HBMappingFactory
{
    private static final Log log = LogFactory.getLog(HBMappingFactory.class);
    private Hashtable<Class,HBMappedBean> m_allPropertyInfos = new Hashtable<Class,HBMappedBean>();
    private static HBMappingFactory m_instance = new HBMappingFactory();
    public static HBMappingFactory getInstance()
    {
        return m_instance;
    }

    private HBMappingFactory()
    {
    }

    public HBMappedBean getHBMapping(Class cls)
    {
        if(null == cls)
        {
            return null;
        }
        if(m_allPropertyInfos.containsKey(cls) == false)
        {
            synchronized(HBMappingFactory.class)
            {
                if(m_allPropertyInfos.containsKey(cls) == false)
                {
                    try
                    {
                        m_allPropertyInfos.put(cls,new HBMappedBean(cls));
                    }
                    catch(HBException ex)
                    {
                        ex.printStackTrace();
                    }
                }
            }
        }
        return(HBMappedBean) m_allPropertyInfos.get(cls);
    }

    public HBMappedBean getHBMapping(Object obj)
    {
        if(null == obj)
        {
            return null;
        }
        return getHBMapping(obj.getClass());
    }

}
